Choose the confidence threshold of a model
A detection or segmentation model gives each object it finds a confidence, from 0 to 100 %. On the line, objects below a threshold are ignored: too low and the model sees things that are not there, too high and it misses real ones. This guide moves the threshold over the test images of a model that finds biscuits, to choose the value to use in the flow.
What you will learn
- What the confidence threshold does to the predictions
- How to see which images go wrong as it moves
- How to choose a value and use it on the line
Before you start
You need an object detection or segmentation model with a finished training. Its results are explained in Read the results of a detection or segmentation model.
1. Judge the images by what matters
Open the results of the model and choose in «Evaluation type» the way your inspection judges a product: «Count matching metrics» when the number of objects matters, as in a pack of four biscuits, «Presence metrics» when one defect is enough to reject it. With either, the evaluation images say whether each one is right at the threshold you choose.

2. Open the evaluation images
Click «Evaluation images». Each test image shows the objects the model found above the threshold, its most and least confident one, and a border: green when the image is right at this threshold, red when it is not. Here eight packs of ten are right at the 25 % the slider starts on; the two red ones miss a biscuit whatever the threshold.

3. Raise the threshold
Move «Confidence threshold» up. Predictions below it disappear, as they would on the line. At 80 % a third pack turns red: one of its biscuits was found with only 55 %, and is now ignored.

4. Find where it breaks
Keep going and the model ends up missing almost every biscuit: at 95 % nearly all the packs are red. The useful range is the one where the most images are right; here, from 5 to 50 %.

5. Choose a value with margin
Choose a value inside the range, with margin on both sides: images from the line are never exactly the test images. Here 50 % keeps every right pack right, and stays far from the 55 % biscuit that breaks at 80 %. A lower value would also do, but lets in weak predictions that are not there yet.

6. Check one image
Click an image to open it. Here, the pack that broke at 80 %: «Worst prediction» says its weakest biscuit was found with 55 %, and the badge at the top right says the image is right at the 50 % chosen.

7. Move the threshold of the image
The viewer has its own «Confidence threshold», for this image only. Move it above 55 %: the weakest biscuit disappears, the model sees three, and the badge turns to «Wrong». It is the quickest way to see what a threshold would do to one product.

Use it on the line
The threshold you choose here is not saved with the model: set it where the model runs.
- In the inferencer node, the «Advanced config» tab holds the minimum confidence of the model: predictions below it never reach the flow. See Run a trained model on an image.
- Or keep every prediction and require the confidence in the rule that decides OK or NOK, as in Decide pass or fail from the predictions.
Check the threshold again after each new training: another model gives other confidences.
Next steps
Recorded on Rosepetal release 1.8.15.